{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-04-28T22:05:17.460286Z",
     "start_time": "2019-04-28T22:05:16.630625Z"
    },
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "#from IPython.display import Image\n",
    "\n",
    "pd.set_option('precision', 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DataFrame合并和添加\n",
    "* Append\n",
    "* Concat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## 创建sample data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker  open        date\n",
       "0    GOOG  1500  2020-01-01\n",
       "1    APPL   300  2020-01-02\n",
       "2    MSFT   200  2020-01-01\n",
       "3  COSTCO   300  2020-01-01\n",
       "4    ZOOM   100  2020-01-02\n",
       "5   YAHOO   150  2020-01-01"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1=pd.DataFrame(\n",
    "{\n",
    "    'ticker':['GOOG','APPL','MSFT','COSTCO','ZOOM','YAHOO'],\n",
    "    'open':[1500,300,200,300,100,150],\n",
    "    'date':['2020-01-01','2020-01-02','2020-01-01','2020-01-01','2020-01-02','2020-01-01']\n",
    "})\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>160</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker  price        date\n",
       "0    GOOG   1000  2020-01-01\n",
       "1    APPL    200  2020-01-02\n",
       "2    MSFT    160  2020-01-01\n",
       "3  COSTCO     20  2020-01-01\n",
       "4    ZOOM     60  2020-01-02\n",
       "5   YAHOO    110  2020-01-01"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2=pd.DataFrame(\n",
    "{\n",
    "    'ticker':['GOOG','APPL','MSFT','COSTCO','ZOOM','YAHOO'],\n",
    "    'price':[1000,200,160,20,60,110],\n",
    "    'date':['2020-01-01','2020-01-02','2020-01-01','2020-01-01','2020-01-02','2020-01-01']\n",
    "})\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ticker    open        date   price\n",
       "0     GOOG  1500.0  2020-01-01     NaN\n",
       "1     APPL   300.0  2020-01-02     NaN\n",
       "2     MSFT   200.0  2020-01-01     NaN\n",
       "3   COSTCO   300.0  2020-01-01     NaN\n",
       "4     ZOOM   100.0  2020-01-02     NaN\n",
       "5    YAHOO   150.0  2020-01-01     NaN\n",
       "6     GOOG     NaN  2020-01-01  1000.0\n",
       "7     APPL     NaN  2020-01-02   200.0\n",
       "8     MSFT     NaN  2020-01-01   160.0\n",
       "9   COSTCO     NaN  2020-01-01    20.0\n",
       "10    ZOOM     NaN  2020-01-02    60.0\n",
       "11   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ticker    open        date   price\n",
       "0     GOOG  1500.0  2020-01-01     NaN\n",
       "1     APPL   300.0  2020-01-02     NaN\n",
       "2     MSFT   200.0  2020-01-01     NaN\n",
       "3   COSTCO   300.0  2020-01-01     NaN\n",
       "4     ZOOM   100.0  2020-01-02     NaN\n",
       "5    YAHOO   150.0  2020-01-01     NaN\n",
       "6     GOOG     NaN  2020-01-01  1000.0\n",
       "7     APPL     NaN  2020-01-02   200.0\n",
       "8     MSFT     NaN  2020-01-01   160.0\n",
       "9   COSTCO     NaN  2020-01-01    20.0\n",
       "10    ZOOM     NaN  2020-01-02    60.0\n",
       "11   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2,ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>price</th>\n",
       "      <th>ticker</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>300.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>APPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>200.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>300.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>COSTCO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>100.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ZOOM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>150.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YAHOO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>GOOG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>200.0</td>\n",
       "      <td>APPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>160.0</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.0</td>\n",
       "      <td>COSTCO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>60.0</td>\n",
       "      <td>ZOOM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>YAHOO</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         date    open   price  ticker\n",
       "0  2020-01-01  1500.0     NaN    GOOG\n",
       "1  2020-01-02   300.0     NaN    APPL\n",
       "2  2020-01-01   200.0     NaN    MSFT\n",
       "3  2020-01-01   300.0     NaN  COSTCO\n",
       "4  2020-01-02   100.0     NaN    ZOOM\n",
       "5  2020-01-01   150.0     NaN   YAHOO\n",
       "0  2020-01-01     NaN  1000.0    GOOG\n",
       "1  2020-01-02     NaN   200.0    APPL\n",
       "2  2020-01-01     NaN   160.0    MSFT\n",
       "3  2020-01-01     NaN    20.0  COSTCO\n",
       "4  2020-01-02     NaN    60.0    ZOOM\n",
       "5  2020-01-01     NaN   110.0   YAHOO"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2,sort=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker    open        date   price\n",
       "0    GOOG  1500.0  2020-01-01     NaN\n",
       "1    APPL   300.0  2020-01-02     NaN\n",
       "2    MSFT   200.0  2020-01-01     NaN\n",
       "3  COSTCO   300.0  2020-01-01     NaN\n",
       "4    ZOOM   100.0  2020-01-02     NaN\n",
       "5   YAHOO   150.0  2020-01-01     NaN\n",
       "0    GOOG     NaN  2020-01-01  1000.0\n",
       "1    APPL     NaN  2020-01-02   200.0\n",
       "2    MSFT     NaN  2020-01-01   160.0\n",
       "3  COSTCO     NaN  2020-01-01    20.0\n",
       "4    ZOOM     NaN  2020-01-02    60.0\n",
       "5   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2,sort=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Concat\n",
    "* 按行合并\n",
    "* 按列合并"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按列合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker    open        date   price\n",
       "0    GOOG  1500.0  2020-01-01     NaN\n",
       "1    APPL   300.0  2020-01-02     NaN\n",
       "2    MSFT   200.0  2020-01-01     NaN\n",
       "3  COSTCO   300.0  2020-01-01     NaN\n",
       "4    ZOOM   100.0  2020-01-02     NaN\n",
       "5   YAHOO   150.0  2020-01-01     NaN\n",
       "0    GOOG     NaN  2020-01-01  1000.0\n",
       "1    APPL     NaN  2020-01-02   200.0\n",
       "2    MSFT     NaN  2020-01-01   160.0\n",
       "3  COSTCO     NaN  2020-01-01    20.0\n",
       "4    ZOOM     NaN  2020-01-02    60.0\n",
       "5   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker    open        date   price\n",
       "0    GOOG  1500.0  2020-01-01     NaN\n",
       "1    APPL   300.0  2020-01-02     NaN\n",
       "2    MSFT   200.0  2020-01-01     NaN\n",
       "3  COSTCO   300.0  2020-01-01     NaN\n",
       "4    ZOOM   100.0  2020-01-02     NaN\n",
       "5   YAHOO   150.0  2020-01-01     NaN\n",
       "0    GOOG     NaN  2020-01-01  1000.0\n",
       "1    APPL     NaN  2020-01-02   200.0\n",
       "2    MSFT     NaN  2020-01-01   160.0\n",
       "3  COSTCO     NaN  2020-01-01    20.0\n",
       "4    ZOOM     NaN  2020-01-02    60.0\n",
       "5   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2,sort=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ticker    open        date   price\n",
       "0     GOOG  1500.0  2020-01-01     NaN\n",
       "1     APPL   300.0  2020-01-02     NaN\n",
       "2     MSFT   200.0  2020-01-01     NaN\n",
       "3   COSTCO   300.0  2020-01-01     NaN\n",
       "4     ZOOM   100.0  2020-01-02     NaN\n",
       "5    YAHOO   150.0  2020-01-01     NaN\n",
       "6     GOOG     NaN  2020-01-01  1000.0\n",
       "7     APPL     NaN  2020-01-02   200.0\n",
       "8     MSFT     NaN  2020-01-01   160.0\n",
       "9   COSTCO     NaN  2020-01-01    20.0\n",
       "10    ZOOM     NaN  2020-01-02    60.0\n",
       "11   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>price</th>\n",
       "      <th>ticker</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>300.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>APPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>200.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>300.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>COSTCO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>100.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ZOOM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>150.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YAHOO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>GOOG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>200.0</td>\n",
       "      <td>APPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>160.0</td>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.0</td>\n",
       "      <td>COSTCO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>60.0</td>\n",
       "      <td>ZOOM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>110.0</td>\n",
       "      <td>YAHOO</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          date    open   price  ticker\n",
       "0   2020-01-01  1500.0     NaN    GOOG\n",
       "1   2020-01-02   300.0     NaN    APPL\n",
       "2   2020-01-01   200.0     NaN    MSFT\n",
       "3   2020-01-01   300.0     NaN  COSTCO\n",
       "4   2020-01-02   100.0     NaN    ZOOM\n",
       "5   2020-01-01   150.0     NaN   YAHOO\n",
       "6   2020-01-01     NaN  1000.0    GOOG\n",
       "7   2020-01-02     NaN   200.0    APPL\n",
       "8   2020-01-01     NaN   160.0    MSFT\n",
       "9   2020-01-01     NaN    20.0  COSTCO\n",
       "10  2020-01-02     NaN    60.0    ZOOM\n",
       "11  2020-01-01     NaN   110.0   YAHOO"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],ignore_index=True,sort=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker        date\n",
       "0    GOOG  2020-01-01\n",
       "1    APPL  2020-01-02\n",
       "2    MSFT  2020-01-01\n",
       "3  COSTCO  2020-01-01\n",
       "4    ZOOM  2020-01-02\n",
       "5   YAHOO  2020-01-01\n",
       "0    GOOG  2020-01-01\n",
       "1    APPL  2020-01-02\n",
       "2    MSFT  2020-01-01\n",
       "3  COSTCO  2020-01-01\n",
       "4    ZOOM  2020-01-02\n",
       "5   YAHOO  2020-01-01"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],join='inner')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ticker    open        date\n",
       "0     GOOG  1500.0  2020-01-01\n",
       "1     APPL   300.0  2020-01-02\n",
       "2     MSFT   200.0  2020-01-01\n",
       "3   COSTCO   300.0  2020-01-01\n",
       "4     ZOOM   100.0  2020-01-02\n",
       "5    YAHOO   150.0  2020-01-01\n",
       "6     GOOG     NaN  2020-01-01\n",
       "7     APPL     NaN  2020-01-02\n",
       "8     MSFT     NaN  2020-01-01\n",
       "9   COSTCO     NaN  2020-01-01\n",
       "10    ZOOM     NaN  2020-01-02\n",
       "11   YAHOO     NaN  2020-01-01"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],ignore_index=True)[df1.columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">df1</th>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">df2</th>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       ticker    open        date   price\n",
       "df1 0    GOOG  1500.0  2020-01-01     NaN\n",
       "    1    APPL   300.0  2020-01-02     NaN\n",
       "    2    MSFT   200.0  2020-01-01     NaN\n",
       "    3  COSTCO   300.0  2020-01-01     NaN\n",
       "    4    ZOOM   100.0  2020-01-02     NaN\n",
       "    5   YAHOO   150.0  2020-01-01     NaN\n",
       "df2 0    GOOG     NaN  2020-01-01  1000.0\n",
       "    1    APPL     NaN  2020-01-02   200.0\n",
       "    2    MSFT     NaN  2020-01-01   160.0\n",
       "    3  COSTCO     NaN  2020-01-01    20.0\n",
       "    4    ZOOM     NaN  2020-01-02    60.0\n",
       "    5   YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df=pd.concat([df1,df2],keys=['df1','df2'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>source</th>\n",
       "      <th>index</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">df1</th>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"6\" valign=\"top\">df2</th>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              ticker    open        date   price\n",
       "source index                                    \n",
       "df1    0        GOOG  1500.0  2020-01-01     NaN\n",
       "       1        APPL   300.0  2020-01-02     NaN\n",
       "       2        MSFT   200.0  2020-01-01     NaN\n",
       "       3      COSTCO   300.0  2020-01-01     NaN\n",
       "       4        ZOOM   100.0  2020-01-02     NaN\n",
       "       5       YAHOO   150.0  2020-01-01     NaN\n",
       "df2    0        GOOG     NaN  2020-01-01  1000.0\n",
       "       1        APPL     NaN  2020-01-02   200.0\n",
       "       2        MSFT     NaN  2020-01-01   160.0\n",
       "       3      COSTCO     NaN  2020-01-01    20.0\n",
       "       4        ZOOM     NaN  2020-01-02    60.0\n",
       "       5       YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],keys=['df1','df2'],names=['source','index'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([('df1', 0),\n",
       "            ('df1', 1),\n",
       "            ('df1', 2),\n",
       "            ('df1', 3),\n",
       "            ('df1', 4),\n",
       "            ('df1', 5),\n",
       "            ('df2', 0),\n",
       "            ('df2', 1),\n",
       "            ('df2', 2),\n",
       "            ('df2', 3),\n",
       "            ('df2', 4),\n",
       "            ('df2', 5)],\n",
       "           )"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>df1</th>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ticker    open        date  price\n",
       "df1 0   GOOG  1500.0  2020-01-01    NaN"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[[('df1', 0)]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>(df1, 0)</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 1)</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 2)</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 3)</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 4)</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 5)</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 0)</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 1)</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 2)</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 3)</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 4)</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 5)</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          ticker    open        date   price\n",
       "(df1, 0)    GOOG  1500.0  2020-01-01     NaN\n",
       "(df1, 1)    APPL   300.0  2020-01-02     NaN\n",
       "(df1, 2)    MSFT   200.0  2020-01-01     NaN\n",
       "(df1, 3)  COSTCO   300.0  2020-01-01     NaN\n",
       "(df1, 4)    ZOOM   100.0  2020-01-02     NaN\n",
       "(df1, 5)   YAHOO   150.0  2020-01-01     NaN\n",
       "(df2, 0)    GOOG     NaN  2020-01-01  1000.0\n",
       "(df2, 1)    APPL     NaN  2020-01-02   200.0\n",
       "(df2, 2)    MSFT     NaN  2020-01-01   160.0\n",
       "(df2, 3)  COSTCO     NaN  2020-01-01    20.0\n",
       "(df2, 4)    ZOOM     NaN  2020-01-02    60.0\n",
       "(df2, 5)   YAHOO     NaN  2020-01-01   110.0\n",
       "0           GOOG  1500.0  2020-01-01     NaN\n",
       "1           APPL   300.0  2020-01-02     NaN\n",
       "2           MSFT   200.0  2020-01-01     NaN\n",
       "3         COSTCO   300.0  2020-01-01     NaN\n",
       "4           ZOOM   100.0  2020-01-02     NaN\n",
       "5          YAHOO   150.0  2020-01-01     NaN\n",
       "0           GOOG     NaN  2020-01-01  1000.0\n",
       "1           APPL     NaN  2020-01-02   200.0\n",
       "2           MSFT     NaN  2020-01-01   160.0\n",
       "3         COSTCO     NaN  2020-01-01    20.0\n",
       "4           ZOOM     NaN  2020-01-02    60.0\n",
       "5          YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.append([df1,df2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>(df1, 0)</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 1)</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 2)</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 3)</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 4)</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df1, 5)</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 0)</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 1)</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 2)</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 3)</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 4)</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>(df2, 5)</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          ticker    open        date   price\n",
       "(df1, 0)    GOOG  1500.0  2020-01-01     NaN\n",
       "(df1, 1)    APPL   300.0  2020-01-02     NaN\n",
       "(df1, 2)    MSFT   200.0  2020-01-01     NaN\n",
       "(df1, 3)  COSTCO   300.0  2020-01-01     NaN\n",
       "(df1, 4)    ZOOM   100.0  2020-01-02     NaN\n",
       "(df1, 5)   YAHOO   150.0  2020-01-01     NaN\n",
       "(df2, 0)    GOOG     NaN  2020-01-01  1000.0\n",
       "(df2, 1)    APPL     NaN  2020-01-02   200.0\n",
       "(df2, 2)    MSFT     NaN  2020-01-01   160.0\n",
       "(df2, 3)  COSTCO     NaN  2020-01-01    20.0\n",
       "(df2, 4)    ZOOM     NaN  2020-01-02    60.0\n",
       "(df2, 5)   YAHOO     NaN  2020-01-01   110.0\n",
       "0           GOOG  1500.0  2020-01-01     NaN\n",
       "1           APPL   300.0  2020-01-02     NaN\n",
       "2           MSFT   200.0  2020-01-01     NaN\n",
       "3         COSTCO   300.0  2020-01-01     NaN\n",
       "4           ZOOM   100.0  2020-01-02     NaN\n",
       "5          YAHOO   150.0  2020-01-01     NaN\n",
       "0           GOOG     NaN  2020-01-01  1000.0\n",
       "1           APPL     NaN  2020-01-02   200.0\n",
       "2           MSFT     NaN  2020-01-01   160.0\n",
       "3         COSTCO     NaN  2020-01-01    20.0\n",
       "4           ZOOM     NaN  2020-01-02    60.0\n",
       "5          YAHOO     NaN  2020-01-01   110.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df,df1,df2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### 按行合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker  open        date  ticker  price        date\n",
       "0    GOOG  1500  2020-01-01    GOOG   1000  2020-01-01\n",
       "1    APPL   300  2020-01-02    APPL    200  2020-01-02\n",
       "2    MSFT   200  2020-01-01    MSFT    160  2020-01-01\n",
       "3  COSTCO   300  2020-01-01  COSTCO     20  2020-01-01\n",
       "4    ZOOM   100  2020-01-02    ZOOM     60  2020-01-02\n",
       "5   YAHOO   150  2020-01-01   YAHOO    110  2020-01-01"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   ticker  open        date\n",
      "0    GOOG  1500  2020-01-01\n",
      "1    APPL   300  2020-01-02\n",
      "2    MSFT   200  2020-01-01\n",
      "3  COSTCO   300  2020-01-01\n",
      "4    ZOOM   100  2020-01-02\n",
      "5   YAHOO   150  2020-01-01\n",
      "   ticker  price        date\n",
      "0    GOOG   1000  2020-01-01\n",
      "1    APPL    200  2020-01-02\n",
      "2    MSFT    160  2020-01-01\n",
      "3  COSTCO     20  2020-01-01\n",
      "4    ZOOM     60  2020-01-02\n",
      "5   YAHOO    110  2020-01-01\n"
     ]
    }
   ],
   "source": [
    "print(df1)\n",
    "print(df2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker  open        date\n",
       "1    GOOG  1500  2020-01-01\n",
       "2    APPL   300  2020-01-02\n",
       "3    MSFT   200  2020-01-01\n",
       "4  COSTCO   300  2020-01-01\n",
       "5    ZOOM   100  2020-01-02\n",
       "6   YAHOO   150  2020-01-01"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.index=[1,2,3,4,5,6]\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker    open        date  ticker   price        date\n",
       "0     NaN     NaN         NaN    GOOG  1000.0  2020-01-01\n",
       "1    GOOG  1500.0  2020-01-01    APPL   200.0  2020-01-02\n",
       "2    APPL   300.0  2020-01-02    MSFT   160.0  2020-01-01\n",
       "3    MSFT   200.0  2020-01-01  COSTCO    20.0  2020-01-01\n",
       "4  COSTCO   300.0  2020-01-01    ZOOM    60.0  2020-01-02\n",
       "5    ZOOM   100.0  2020-01-02   YAHOO   110.0  2020-01-01\n",
       "6   YAHOO   150.0  2020-01-01     NaN     NaN         NaN"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker  open        date  ticker  price        date\n",
       "1    GOOG  1500  2020-01-01    APPL    200  2020-01-02\n",
       "2    APPL   300  2020-01-02    MSFT    160  2020-01-01\n",
       "3    MSFT   200  2020-01-01  COSTCO     20  2020-01-01\n",
       "4  COSTCO   300  2020-01-01    ZOOM     60  2020-01-02\n",
       "5    ZOOM   100  2020-01-02   YAHOO    110  2020-01-01"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],join='inner',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">df1</th>\n",
       "      <th colspan=\"3\" halign=\"left\">df2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      df1                         df2                    \n",
       "   ticker    open        date  ticker   price        date\n",
       "0     NaN     NaN         NaN    GOOG  1000.0  2020-01-01\n",
       "1    GOOG  1500.0  2020-01-01    APPL   200.0  2020-01-02\n",
       "2    APPL   300.0  2020-01-02    MSFT   160.0  2020-01-01\n",
       "3    MSFT   200.0  2020-01-01  COSTCO    20.0  2020-01-01\n",
       "4  COSTCO   300.0  2020-01-01    ZOOM    60.0  2020-01-02\n",
       "5    ZOOM   100.0  2020-01-02   YAHOO   110.0  2020-01-01\n",
       "6   YAHOO   150.0  2020-01-01     NaN     NaN         NaN"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s=pd.concat([df1,df2],axis=1,keys=['df1','df2'])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>source</th>\n",
       "      <th colspan=\"3\" halign=\"left\">df1</th>\n",
       "      <th colspan=\"3\" halign=\"left\">df2</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>columns</th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "source      df1                         df2                    \n",
       "columns  ticker    open        date  ticker   price        date\n",
       "0           NaN     NaN         NaN    GOOG  1000.0  2020-01-01\n",
       "1          GOOG  1500.0  2020-01-01    APPL   200.0  2020-01-02\n",
       "2          APPL   300.0  2020-01-02    MSFT   160.0  2020-01-01\n",
       "3          MSFT   200.0  2020-01-01  COSTCO    20.0  2020-01-01\n",
       "4        COSTCO   300.0  2020-01-01    ZOOM    60.0  2020-01-02\n",
       "5          ZOOM   100.0  2020-01-02   YAHOO   110.0  2020-01-01\n",
       "6         YAHOO   150.0  2020-01-01     NaN     NaN         NaN"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],axis=1,keys=['df1','df2'],names=['source','columns'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex([('df1', 'ticker'),\n",
       "            ('df1',   'open'),\n",
       "            ('df1',   'date'),\n",
       "            ('df2', 'ticker'),\n",
       "            ('df2',  'price'),\n",
       "            ('df2',   'date')],\n",
       "           )"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>df1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      df1\n",
       "   ticker\n",
       "0     NaN\n",
       "1    GOOG\n",
       "2    APPL\n",
       "3    MSFT\n",
       "4  COSTCO\n",
       "5    ZOOM\n",
       "6   YAHOO"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s[[('df1', 'ticker')]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        0       1           2       3       4           5\n",
       "0     NaN     NaN         NaN    GOOG  1000.0  2020-01-01\n",
       "1    GOOG  1500.0  2020-01-01    APPL   200.0  2020-01-02\n",
       "2    APPL   300.0  2020-01-02    MSFT   160.0  2020-01-01\n",
       "3    MSFT   200.0  2020-01-01  COSTCO    20.0  2020-01-01\n",
       "4  COSTCO   300.0  2020-01-01    ZOOM    60.0  2020-01-02\n",
       "5    ZOOM   100.0  2020-01-02   YAHOO   110.0  2020-01-01\n",
       "6   YAHOO   150.0  2020-01-01     NaN     NaN         NaN"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2],axis=1,ignore_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "      <th>(df1, ticker)</th>\n",
       "      <th>(df1, open)</th>\n",
       "      <th>(df1, date)</th>\n",
       "      <th>(df2, ticker)</th>\n",
       "      <th>(df2, price)</th>\n",
       "      <th>(df2, date)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ticker    open        date  ticker   price        date (df1, ticker)  \\\n",
       "0     NaN     NaN         NaN    GOOG  1000.0  2020-01-01           NaN   \n",
       "1    GOOG  1500.0  2020-01-01    APPL   200.0  2020-01-02          GOOG   \n",
       "2    APPL   300.0  2020-01-02    MSFT   160.0  2020-01-01          APPL   \n",
       "3    MSFT   200.0  2020-01-01  COSTCO    20.0  2020-01-01          MSFT   \n",
       "4  COSTCO   300.0  2020-01-01    ZOOM    60.0  2020-01-02        COSTCO   \n",
       "5    ZOOM   100.0  2020-01-02   YAHOO   110.0  2020-01-01          ZOOM   \n",
       "6   YAHOO   150.0  2020-01-01     NaN     NaN         NaN         YAHOO   \n",
       "\n",
       "   (df1, open) (df1, date) (df2, ticker)  (df2, price) (df2, date)  \n",
       "0          NaN         NaN          GOOG        1000.0  2020-01-01  \n",
       "1       1500.0  2020-01-01          APPL         200.0  2020-01-02  \n",
       "2        300.0  2020-01-02          MSFT         160.0  2020-01-01  \n",
       "3        200.0  2020-01-01        COSTCO          20.0  2020-01-01  \n",
       "4        300.0  2020-01-01          ZOOM          60.0  2020-01-02  \n",
       "5        100.0  2020-01-02         YAHOO         110.0  2020-01-01  \n",
       "6        150.0  2020-01-01           NaN           NaN         NaN  "
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2,s],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "      <th>ticker</th>\n",
       "      <th>open</th>\n",
       "      <th>date</th>\n",
       "      <th>ticker</th>\n",
       "      <th>price</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>GOOG</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>APPL</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>APPL</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>160.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>200.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>COSTCO</td>\n",
       "      <td>300.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>60.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>ZOOM</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>110.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>GOOG</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>YAHOO</td>\n",
       "      <td>150.0</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>APPL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>200.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MSFT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>160.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>COSTCO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>20.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ZOOM</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>60.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>YAHOO</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>110.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ticker    open        date   price  ticker    open        date  ticker  \\\n",
       "0     GOOG  1500.0  2020-01-01     NaN     NaN     NaN         NaN    GOOG   \n",
       "1     APPL   300.0  2020-01-02     NaN    GOOG  1500.0  2020-01-01    APPL   \n",
       "2     MSFT   200.0  2020-01-01     NaN    APPL   300.0  2020-01-02    MSFT   \n",
       "3   COSTCO   300.0  2020-01-01     NaN    MSFT   200.0  2020-01-01  COSTCO   \n",
       "4     ZOOM   100.0  2020-01-02     NaN  COSTCO   300.0  2020-01-01    ZOOM   \n",
       "5    YAHOO   150.0  2020-01-01     NaN    ZOOM   100.0  2020-01-02   YAHOO   \n",
       "6     GOOG     NaN  2020-01-01  1000.0   YAHOO   150.0  2020-01-01     NaN   \n",
       "7     APPL     NaN  2020-01-02   200.0     NaN     NaN         NaN     NaN   \n",
       "8     MSFT     NaN  2020-01-01   160.0     NaN     NaN         NaN     NaN   \n",
       "9   COSTCO     NaN  2020-01-01    20.0     NaN     NaN         NaN     NaN   \n",
       "10    ZOOM     NaN  2020-01-02    60.0     NaN     NaN         NaN     NaN   \n",
       "11   YAHOO     NaN  2020-01-01   110.0     NaN     NaN         NaN     NaN   \n",
       "\n",
       "     price        date  \n",
       "0   1000.0  2020-01-01  \n",
       "1    200.0  2020-01-02  \n",
       "2    160.0  2020-01-01  \n",
       "3     20.0  2020-01-01  \n",
       "4     60.0  2020-01-02  \n",
       "5    110.0  2020-01-01  \n",
       "6      NaN         NaN  \n",
       "7      NaN         NaN  \n",
       "8      NaN         NaN  \n",
       "9      NaN         NaN  \n",
       "10     NaN         NaN  \n",
       "11     NaN         NaN  "
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df.reset_index(drop=True),df1,df2],axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 课后习题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import io\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "pd.set_option('precision', 2)\n",
    "prc = pd.read_csv(\n",
    "    io.StringIO('ticker,open,date,close\\nAAPL,426.23,2018-01-04,435.23\\nMSFT,42.3,2018-01-04,51.3\\nAAPL,436.23,2018-01-05,\\nMSFT,52.3,2018-01-05,\\n'),\n",
    "    parse_dates=['date']\n",
    ")\n",
    "prc2 = prc.assign(\n",
    "    date=pd.to_datetime('2018-01-06'),\n",
    "    close=prc.open + np.random.randn(len(prc.open))\n",
    ").drop('open', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "volume = pd.DataFrame({\n",
    "    'ticker': ['AAPL', 'MSFT', 'IBM', 'YHOO', 'GOOG'],\n",
    "    'volume': [1954.73,  335.83,  362.79,  858.18,  629.79]\n",
    "}).assign(date=pd.to_datetime('2018-01-05'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过append, 合并prc2 和prc, 保证index不重复"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "应用 pd.concat, 合并prc和prc2：\n",
    "* 确保index不重复\n",
    "* 只保留在prc和prc2都出现的column，从新产生一个index\n",
    "* 结果包括MultiIndex，用prc或prc2表示每个dataframe"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "288px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
